<?php

namespace App\ZL\CrawlerExpansion;

use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
use Symfony\Component\DomCrawler\Crawler;

class Get66Movie
{
    public function run()
    {
        header("Content-type: text/html; charset=utf-8");
        set_time_limit(0);
//        $driver = RemoteWebDriver::create(
//            'http://127.0.0.1:8910',DesiredCapabilities::phantomjs(),
//        );
        $host = '127.0.0.1:8910';
        $capabilities = array(
            WebDriverCapabilityType::BROWSER_NAME => 'phantomjs',
            'phantomjs.page.settings.userAgent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0',
        );
        $driver = RemoteWebDriver::create($host, $capabilities, 5000);
        $driver->manage()->timeouts()->pageLoadTimeout(300)->implicitlyWait(300)->setScriptTimeout(300);
        $driver->executor->setRequestTimeout(5000);
        $driver->executor->setConnectionTimeout(5000);
        $driver->get('http://www.dygang.com/');
        $crawler = new Crawler($driver->getPageSource());
        dump($crawler->html());
//        $crawler->filter('img')->each(function (Crawler $node,$i) {
//            $_img_src = $node->attr('src');
//            $_url = $node->parents()->attr('href');
//            if(FileTool::checkHttpPrefix($_img_src)){
//                FileTool::downloadJpg($_img_src,'./tmp/');
//            }
////            $_img = $node->filter('img')->attr('src');
////            print $_img."<br/>";
////            error_log($node->text()."\n", 3, 'errors.log');
//        });
//        dump($crawler->filter('a')->first()->attr('href'));
//        dump($driver->getPageSource());
//        $crawler->


    }
}